﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace SF.Base.Core {
	public class SettingRules {
		/// <summary>
		/// 获取系统配置
		/// </summary>
		/// <returns></returns>
		public static List<SettingEntity> GetSettings(string connStr) {

			List<SettingEntity> lists = new List<SettingEntity>();

			try {
				using (
					IDataReader iReader = Sh.ExecuteReader(
						connStr, 
						CommandType.Text, 
						@"
							select 
								sid,setting_id,parakey,paravalue,paratype,paradesc,adddate,status 
							from dt_settings", 
						null
					)
				) {
					while (iReader.Read()) {
						IDataRecord iRecord = iReader as IDataRecord;

						SettingEntity tb = new SettingEntity();

						tb.SId = Sh.GetInt(iRecord, "sid");
						tb.SettingId = Sh.GetStr(iRecord, "setting_id");
						tb.Key = Sh.GetStr(iRecord, "ParaKey");
						tb.Value = Sh.GetStr(iRecord, "ParaValue");
						tb.Type = Sh.GetStr(iRecord, "ParaType");
						tb.Description = Sh.GetStr(iRecord, "ParaDesc");
						tb.AddDate = Sh.GetDate(iRecord, "AddDate");
						tb.Status = Sh.GetInt(iRecord, "status");

						lists.Add(tb);
					}
					Logger.Detail("GetSettings()", lists.Count.ToString());
					return lists;
				}
			}
			catch (System.Exception e) {
				throw new Exception("查询系统配置出错！", e);
			}
		}

	}
}
